<template>
    <el-form :model="form" label-width="120px">
      <el-form-item label="Activity name">
        <el-input v-model="form.ename" />
      </el-form-item>
        <el-form-item label=" 部门">
            <DeptSelect @select-change="selectChange" 
            :initvalue="form.deptno"></DeptSelect>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="onSubmit">
                Create
            </el-button>
            <el-button>Cancel</el-button>
      </el-form-item>


      <el-form-item label=" 入职时间">
        <el-date-picker 
            v-model="form.hiredate"
            type="daterange"
            range-separator="到"
            placeholder="选择日期"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :disabledDate="hiredateDisabledDate"
            :shortcuts="hiredateShortcuts"
            value-format="YYYY-MM-DD"
            format="YYYY年/MM月/DD日"
            
        />
        </el-form-item>


    </el-form>
  </template>
  
  <script lang="ts" setup>
  import { ref } from 'vue'
//   1.导入自定义组件
import  DeptSelect  from "../dept/DeptSelect.vue";

const hiredateDisabledDate=(time)=>
    time.getTime() > new Date().getTime()
    const hiredateShortcuts = [
  {
    text: '昨天',
    value: () => {
      let now = new Date().getTime()
      now -= 86400000
      return new Date().setTime(now)
    }
  },
  {
    text: '前天',
    value: () => {
      let now = new Date().getTime()
      now -= 86400000
      now -= 86400000
      return new Date().setTime(now)
    }
  },
  {
    text: '大前天',
    value: () => {
      let now = new Date().getTime()
      now -= 86400000
      now -= 86400000
      now -= 86400000
      return new Date().setTime(now)
    }
  }
]
  // do not use same name with ref
  const form = ref({
  ename: 'ysu',
  deptno: 13,
  hiredate: new Date()
})
  
  const onSubmit = () => {
    console.log('submit!',form.value)
  }

  const selectChange= (deptno) => {
    form.value.deptno = deptno;
    console.log("hh2:",deptno);
    
  }
  </script>
